package cn.kgc.crowdfundingadmin03.service;


import cn.kgc.crowdfundingadmin03.mapper.AdvertisementMapper;
import cn.kgc.crowdfundingadmin03.pojo.Advertisement;
import cn.kgc.crowdfundingadmin03.pojo.AdvertisementExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shkstart
 * @create 2020-03-01 13:25
 */
@Service("advertisementService")
public class AdvertisementServiceImpl implements AdvertisementService {

    @Resource
    AdvertisementMapper advertisementMapper;

    @Override
    public PageInfo<Advertisement> getAllAdvertisement(Integer pageNum, Integer pageSize, String keyWord) {
        PageHelper.startPage(pageNum, pageSize);
        AdvertisementExample example = new AdvertisementExample();
        AdvertisementExample.Criteria criteria = example.createCriteria();
        criteria.andNameLike("%" + keyWord + "%");
        List<Advertisement> advertisements = advertisementMapper.selectByExample(example);
        PageInfo<Advertisement> pageInfo = new PageInfo<>(advertisements);
        return pageInfo;
    }

    @Override
    public List<Advertisement> getAll(List<Integer> advertisementIdList) {
        AdvertisementExample example = new AdvertisementExample();
        AdvertisementExample.Criteria criteria = example.createCriteria();
        criteria.andIdIn(advertisementIdList);
        List<Advertisement> advertisements = advertisementMapper.selectByExample(example);
        return advertisements;
    }

    @Override
    public void batchRemove(List<Integer> advertisementIdList) {
        AdvertisementExample example = new AdvertisementExample();
        AdvertisementExample.Criteria criteria = example.createCriteria();
        criteria.andIdIn(advertisementIdList);
        advertisementMapper.deleteByExample(example);
    }

    @Override
    public void saveAd(Advertisement advertisement) {
        advertisementMapper.insert(advertisement);
    }


    @Override
    public void updateCert(Advertisement advertisement) {
        advertisementMapper.updateByPrimaryKeySelective(advertisement);
    }


}
